package com.hpf.lease.web.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hpf.lease.common.result.Result;
import com.hpf.lease.model.bean.LeaseAgreement;
import com.hpf.lease.web.admin.dto.AgreementSearchSubmitDto;
import com.hpf.lease.web.admin.service.LeaseAgreementService;
import com.hpf.lease.web.admin.vo.LeaseAgreementInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/agreement")
@Tag(name = "租约管理模块")
public class AgreementController {
    @Resource
    LeaseAgreementService agreementService;

    @PostMapping("/updateStatusById")
    @Operation(summary = "根据id更新租约状态")
    public Result<Object> updateStatusById(@RequestParam long id ,
                                           @RequestParam String status){
        return Result.build(agreementService.update(Wrappers.lambdaUpdate(LeaseAgreement.class)
                .eq(LeaseAgreement::getId , id)
                .set(LeaseAgreement::getStatus , status)));
    }
    @PostMapping("/saveOrUpdate")
    @Operation(summary = "保存或修改租约信息")
    public Result<Object> saveOrUpdateInfo(@RequestBody LeaseAgreement leaseAgreement){
        return Result.build(agreementService.saveOrUpdateInfo(leaseAgreement));
    }
    @GetMapping
    @Operation(summary = "根据id查询租约信息")
    public Result<LeaseAgreementInfoVo> getDetailById(@RequestParam long id){
        return Result.ok(agreementService.getDetailById(id));
    }
    @GetMapping("/page")
    @Operation(summary = "根据条件分页查询租约列表")
    public Result<Page<LeaseAgreementInfoVo>> getPage(AgreementSearchSubmitDto submitDto){
        return Result.ok(agreementService.getPage(submitDto));
    }
    @DeleteMapping("/removeById")
    @Operation(summary = "根据id删除租约信息")
    public Result<Object> removeById(@RequestParam long id){
        return Result.build(agreementService.removeById(id));
    }
}
